/*
 * Copyright (c) 2009 XMock contributors
 * This program is made available under the terms of the Apache License.
 */
package org.xmock.controller;

import org.apache.log4j.Logger;
import org.xmock.exception.MockException;


public abstract class MockFactory 
{	
	private static final Logger logger = Logger.getLogger(MockFactory.class);
	private static final String MOCK_FACTORY_PROPERTY = "com.barclaycard.xmock.controller.MockFactory";
	
	public MockFactory()
	{		
	}

    public static MockFactory getInstance() throws MockException
    {
        try
        {
        	MockFactory mockFactory = (MockFactory)FactoryFinder.find(MOCK_FACTORY_PROPERTY);
            if(mockFactory != null)
                return mockFactory;
        }
        catch(Exception exception)
        {
        	logger.error("Unable to create Mock Object Factory: " , exception);
            throw new MockException("Unable to create Mock Object Factory: " + exception.getMessage());
        }
    	logger.info("Using default mock factory");
        return defaultInstance();
    }

    public static MockFactory defaultInstance() throws MockException
    {
        return DefaultMockFactory.getInstance();
    }
    
    public abstract MockObjectManager createMockObjectManager();
    
    public abstract MockCaseManager createMockCaseManager();
}
